﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MedReg
{
    public partial class DiplomaEducation
    {
        public void ImportList(List<Classes.DiplomaEducation> DiplomaEducationList)
        {
            var mdb = new MedregDBDataContext();

            var sType = new Classes.EducationType();
            var Type = new Type();
            Type.ImportList(sType.getEducationTypeList(DiplomaEducationList));

            var sSpec = new Classes.Speciality();
            var Spec = new Speciality();
            Spec.ImportList(sSpec.getSpecialityList(DiplomaEducationList));

            var sEdIst = new Classes.EducationInstitution();
            var EdInst = new EducationInstitution();
            EdInst.ImportList(sEdIst.getEducationInstitutionList(DiplomaEducationList));



            foreach (Classes.DiplomaEducation diplomaEducation in DiplomaEducationList)
            {
                var diplomaEducation1 = new DiplomaEducation
                {
                    GraduatedFrom = diplomaEducation.GraduatedFrom.ID,
                    EducationType = diplomaEducation.Type.ID,
                    GraduationDate = diplomaEducation.GraduationDate,
                    DiplomaSerie = diplomaEducation.DiplomaSerie,
                    DiplomaNumber = diplomaEducation.DiplomaNumber,
                    GraduationSpeciality = diplomaEducation.GraduationSpeciality.ID,
                    Employee = diplomaEducation.Employee.ID
                };

                IEnumerable<DiplomaEducation> query = (from cr in mdb.DiplomaEducation
                                                    where cr.Employee == diplomaEducation.Employee.ID
                                                    select cr
                                                   ).ToList();
                mdb.DiplomaEducation.DeleteAllOnSubmit(query);
                mdb.DiplomaEducation.InsertOnSubmit(diplomaEducation1);
            }
            mdb.SubmitChanges();
        }
    }
}
